﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Micronet.OpenWeb.Com.BLL;
using Micronet.OpenWeb.Com.Controls;
using Micronet.OpenWeb.Utils;

namespace Micronet.OpenWeb.OpenWeb.Admin.Views.Shared.Blog
{
    public partial class BlogArticlesAdmin : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void IsEnabledCheckBox_CheckedChanged(object sender, EventArgs e)
        {

            var IsEnabledCbb = (OwCheckBox)sender;
            var obj = OwBlogArticlesBLL.OwGetEntity(IsEnabledCbb.Text.Trim().OwToInt64TryParse());
            obj.IsEnabled = IsEnabledCbb.Checked.ToString().OwToBoolean();
            if (OwBlogArticlesBLL.OwSave(obj) > 0)
            {
                BlogArticledv.Rebind();
                Alert();
            }
        }

        protected void IsHomeDisplayCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            var isHomeDisplayCheckBox = (OwCheckBox)sender;
            var obj = OwBlogArticlesBLL.OwGetEntity(isHomeDisplayCheckBox.Text.Trim().OwToInt64TryParse());
            obj.IsHomeDisplay = isHomeDisplayCheckBox.Checked.ToString().OwToBoolean();
            if (OwBlogArticlesBLL.OwSave(obj) > 0)
            {
                BlogArticledv.Rebind();
                Alert();
            }
        }

        protected void IsHotCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            var isHotCheckBox = (OwCheckBox)sender;
            var obj = OwBlogArticlesBLL.OwGetEntity(isHotCheckBox.Text.Trim().OwToInt64TryParse());
            obj.IsHot = isHotCheckBox.Checked.ToString().OwToBoolean();
            if (OwBlogArticlesBLL.OwSave(obj) > 0)
            {
                BlogArticledv.Rebind();
                Alert();
            }
        }

        protected void IsDraftCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            var isDraftCheckBox = (OwCheckBox)sender;
            var obj = OwBlogArticlesBLL.OwGetEntity(isDraftCheckBox.Text.Trim().OwToInt64TryParse());

            if (OwBlogArticlesBLL.OwSave(obj) > 0)
            {
                BlogArticledv.Rebind();
                Alert();
            }
        }

        protected void IsDeletedCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            var isDeletedCheckBox = (OwCheckBox)sender;
            var obj = OwBlogArticlesBLL.OwGetEntity(isDeletedCheckBox.Text.Trim().OwToInt64TryParse());
            obj.IsDeleted = isDeletedCheckBox.Checked.ToString().OwToBoolean();
            if (OwBlogArticlesBLL.OwSave(obj) > 0)
            {
                BlogArticledv.Rebind();
                Alert();
            }
        }


        protected void Alert()
        {
            //MessageNotification.Text = Resources.OpenWeb.ItemUpdateSuccessfullyLabel;
            //MessageNotification.Title = Resources.OpenWeb.ItemUpdateSuccessfullyLabel;
            //MessageNotification.Show();
        }
        
        protected void AllowSendPingBackCbb_CheckedChanged(object sender, EventArgs e)
        {
            var AllowSendPingBack = (OwCheckBox)sender;
            var obj = OwBlogArticlesBLL.OwGetEntity(AllowSendPingBack.Text.Trim().OwToInt64TryParse());
            obj.AllowSendPingbackTrackback = AllowSendPingBack.Checked.ToString().OwToBoolean();
            if (OwBlogArticlesBLL.OwSave(obj) > 0)
            {
                BlogArticledv.Rebind();
                Alert();
            }
        }

        protected void AllowReceivePingBackCbb_CheckedChanged(object sender, EventArgs e)
        {
            var AllowReceivePingBack = (OwCheckBox)sender;
            var obj = OwBlogArticlesBLL.OwGetEntity(AllowReceivePingBack.Text.Trim().OwToInt64TryParse());
            obj.AllowReceivePingbackTrackback = AllowReceivePingBack.Checked.ToString().OwToBoolean();
            if (OwBlogArticlesBLL.OwSave(obj) > 0)
            {
                BlogArticledv.Rebind();
                Alert();
            }
        }
    }
}